package com.backend.controller;

import com.backend.utils.JacksonUtils;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;


/**
 * @Description:
 * @Author: tanglingyu
 * @CreateDate: 2024/7/1 15:09
 * @Version: 1.0
 */
@RestController
@Slf4j
public class Se5LoginController {

  @Autowired
  private RestTemplate restTemplate;

  @GetMapping("/login")
  public void login(@RequestParam("userName") String userName, @RequestParam String passwords) {
    final LoginDto loginDto = new LoginDto();
    loginDto.setUserName(userName);
    loginDto.setPasswords(passwords);
    final ResponseEntity<String> resp = restTemplate.postForEntity("http://127.0.0.1:8080/bitmain/v1/ssm/software/device/login", loginDto, String.class);
    if (HttpStatus.OK.equals(resp.getStatusCode())) {
      log.info("响应={}", JacksonUtils.toJsonString(resp.getBody()));
    }
  }

  @Getter
  @Setter
  static class LoginDto {

    private String userName;

    private String passwords;

  }

}
